package com.oro.domain;

import static javax.persistence.CascadeType.ALL;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

/**
 * Entity implementation class for Entity: Studente
 * 
 */
@Entity
public class Studente extends Contatto implements Serializable {

	private static final long serialVersionUID = 1L;

	private boolean bankAccount;

	private String bankAccountNote;

	private String codiceFiscale;

	@ManyToMany(cascade = ALL)
	@JoinTable
	// Uni-directional
	private List<Contatto> contattiDiEmergenza;
	private Date dataNascita;

	@Transient
	private Contatto emergencyContactToRemove;
	private boolean englishCourse;

	private String englishCourseNote;
	private Date entryTime;

	private boolean insurance;
	private String insuranceNote;

	@OneToMany(mappedBy = "studente", cascade = ALL)
	private List<Iscrizione> iscrizioni;
	private boolean migrationAgent;

	private String migrationAgentNote;
	@OneToMany(mappedBy = "student", cascade = ALL)
	private List<MigrationAgentReferral> migrationAgentReferrals;

	private String notes;
	private boolean professionalCourse;

	private String professionalCourseNote;
	private boolean skilledVisa;

	private String skilledVisaNote;
	private boolean sponsorVisa;

	private String sponsorVisaNote;
	@OneToOne(cascade = ALL)
	@JoinTable(name = "studente_staydetails")
	private StayDetails stayDetails;

	private boolean studentVisa;
	private String studentVisaNote;

	private boolean touristVisa;

	private String touristVisaNote;

	private boolean translations;

	private String translationsNote;

	@OneToMany(mappedBy = "student", cascade = ALL)
	// Bi-directional
	private List<TranslatorReferral> translatorReferrals;

	private boolean whv;

	private String whvNote;

	public Studente() {
		super();
		contattiDiEmergenza = new ArrayList<Contatto>();
		iscrizioni = new ArrayList<Iscrizione>();
		migrationAgentReferrals = new ArrayList<MigrationAgentReferral>();
		contattiDiEmergenza = new ArrayList<Contatto>();
		iscrizioni = new ArrayList<Iscrizione>();
		stayDetails = new StayDetails();
	}

	public Studente(String name, String surname) {
		this();
		setFirstName(name);
		setSurname(surname);		
	}

	public boolean add(Contatto contact) {
		// return emails.add(email); // this does not work
		if (this.has(contact))
			return false;
		contattiDiEmergenza.add(contact);
		return true;
	}

	public boolean addEmptyEmergencyContact() {
		return add(new Contatto());
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null)
			return false;
		if (!(o instanceof Studente))
			return false;
		Studente s = (Studente) o;
		if (getId() != null)
			return getId().equals(s.getId());
		else {
			if (!(getFirstName() == s.getFirstName()))
				return false;
			if (!(getMiddleName() == s.getMiddleName()))
				return false;
			if (!(getSurname() == s.getSurname()))
				return false;
			if (getIndirizziIt() != null)
				return getIndirizziIt().equals(s.getIndirizziIt());
			if (getIndirizziIt() == null)
				return s.getIndirizziIt() == null;
			if (getIndirizziAu() != null)
				return getIndirizziAu().equals(s.getIndirizziAu());
			if (getIndirizziAu() == null)
				return s.getIndirizziAu() == null;
			return true;
		}

	}

	public boolean getBankAccount() {
		return bankAccount;
	}

	public String getBankAccountNote() {
		return bankAccountNote;
	}

	public String getCodiceFiscale() {
		return codiceFiscale;
	}

	public List<Contatto> getContattiDiEmergenza() {
		return contattiDiEmergenza;
	}

	public Date getDataNascita() {
		return dataNascita;
	}

	public Contatto getEmergencyContactToRemove() {
		return emergencyContactToRemove;
	}

	public boolean getEnglishCourse() {
		return englishCourse;
	}

	public String getEnglishCourseNote() {
		return englishCourseNote;
	}

	public Date getEntryTime() {
		return entryTime;
	}

	public boolean getInsurance() {
		return insurance;
	}

	public String getInsuranceNote() {
		return insuranceNote;
	}

	public List<Iscrizione> getIscrizioni() {
		return iscrizioni;
	}

	public boolean getMigrationAgent() {
		return migrationAgent;
	}

	public String getMigrationAgentNote() {
		return migrationAgentNote;
	}

	public List<MigrationAgentReferral> getMigrationAgentReferrals() {
		return migrationAgentReferrals;
	}

	public String getNotes() {
		return notes;
	}

	public boolean getProfessionalCourse() {
		return professionalCourse;
	}

	public String getProfessionalCourseNote() {
		return professionalCourseNote;
	}

	public boolean getSkilledVisa() {
		return skilledVisa;
	}

	public String getSkilledVisaNote() {
		return skilledVisaNote;
	}

	public boolean getSponsorVisa() {
		return sponsorVisa;
	}

	public String getSponsorVisaNote() {
		return sponsorVisaNote;
	}

	public StayDetails getStayDetails() {
		return stayDetails;
	}

	public boolean getStudentVisa() {
		return studentVisa;
	}

	public String getStudentVisaNote() {
		return studentVisaNote;
	}

	public boolean getTouristVisa() {
		return touristVisa;
	}

	public String getTouristVisaNote() {
		return touristVisaNote;
	}

	public boolean getTranslations() {
		return translations;
	}

	public String getTranslationsNote() {
		return translationsNote;
	}

	public List<TranslatorReferral> getTranslatorReferrals() {
		return translatorReferrals;
	}

	public boolean getWhv() {
		return whv;
	}

	public String getWhvNote() {
		return whvNote;
	}

	public boolean has(Contatto contact) {
		return contattiDiEmergenza.contains(contact);
	}

	public boolean remove(Contatto contact) {
		return contattiDiEmergenza.remove(contact);
	}

	public void removeEmergencyContact() {
		getContattiDiEmergenza().remove(emergencyContactToRemove);
	}

	public void setBankAccount(boolean bankAccount) {
		this.bankAccount = bankAccount;
	}

	public void setBankAccountNote(String bankAccountNote) {
		this.bankAccountNote = bankAccountNote;
	}

	public void setCodiceFiscale(String codiceFiscale) {
		this.codiceFiscale = codiceFiscale;
	}

	public void setContattiDiEmergenza(List<Contatto> contattiDiEmergenza) {
		this.contattiDiEmergenza = contattiDiEmergenza;
	}

	public void setDataNascita(Date dataNascita) {
		this.dataNascita = dataNascita;
	}

	public void setEmergencyContactToRemove(Contatto emergencyContactToRemove) {
		this.emergencyContactToRemove = emergencyContactToRemove;
	}

	public void setEnglishCourse(boolean englishCourse) {
		this.englishCourse = englishCourse;
	}

	public void setEnglishCourseNote(String englishCourseNote) {
		this.englishCourseNote = englishCourseNote;
	}

	public void setEntryTime(Date entryTime) {
		this.entryTime = entryTime;
	}

	public void setInsurance(boolean insurance) {
		this.insurance = insurance;
	}

	public void setInsuranceNote(String insuranceNote) {
		this.insuranceNote = insuranceNote;
	}

	public void setIscrizioni(List<Iscrizione> iscrizioni) {
		this.iscrizioni = iscrizioni;
	}

	public void setMigrationAgent(boolean migrationAgent) {
		this.migrationAgent = migrationAgent;
	}

	public void setMigrationAgentNote(String migrationAgentNote) {
		this.migrationAgentNote = migrationAgentNote;
	}

	public void setMigrationAgentReferrals(
			List<MigrationAgentReferral> migrationAgentReferrals) {
		this.migrationAgentReferrals = migrationAgentReferrals;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public void setProfessionalCourse(boolean professionalCourse) {
		this.professionalCourse = professionalCourse;
	}

	public void setProfessionalCourseNote(String professionalCourseNote) {
		this.professionalCourseNote = professionalCourseNote;
	}

	public void setSkilledVisa(boolean skilledVisa) {
		this.skilledVisa = skilledVisa;
	}

	public void setSkilledVisaNote(String skilledVisaNote) {
		this.skilledVisaNote = skilledVisaNote;
	}

	public void setSponsorVisa(boolean sponsorVisa) {
		this.sponsorVisa = sponsorVisa;
	}

	public void setSponsorVisaNote(String sponsorVisaNote) {
		this.sponsorVisaNote = sponsorVisaNote;
	}

	public void setStayDetails(StayDetails stayDetails) {
		this.stayDetails = stayDetails;
	}

	public void setStudentVisa(boolean studentVisa) {
		this.studentVisa = studentVisa;
	}

	public void setStudentVisaNote(String studentVisaNote) {
		this.studentVisaNote = studentVisaNote;
	}

	public void setTouristVisa(boolean touristVisa) {
		this.touristVisa = touristVisa;
	}

	public void setTouristVisaNote(String touristVisaNote) {
		this.touristVisaNote = touristVisaNote;
	}

	public void setTranslations(boolean translations) {
		this.translations = translations;
	}

	public void setTranslationsNote(String translationsNote) {
		this.translationsNote = translationsNote;
	}

	public void setTranslatorReferrals(
			List<TranslatorReferral> translatorReferrals) {
		this.translatorReferrals = translatorReferrals;
	}

	public void setWhv(boolean whv) {
		this.whv = whv;
	}

	public void setWhvNote(String whvNote) {
		this.whvNote = whvNote;
	}

}
